package springcloud.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;


/**
 * @author xiaolong
 * @version 1.0
 * @description: TODO
 * @date 2021/9/23 14:19
 */
@Component
@EnableBinding(Sink.class)     //消费者是Sink
public class ReceiveMessageListenerController {

    @Value("${server.port}")
    private String serverPort;


    /**
     * @param
     * @return
     * @description: 接收消息
     */
    @StreamListener(Sink.INPUT)   //监听到消息
    public void input(Message<String> message) { //通过Message对象接收

        //message。getPayload 获取消息
        System.out.println("消费者1号，----》接收到的消息：" + message.getPayload() + "\t port: " + serverPort);
    }
}
